﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Linq;
using KC.DataAccess.MV6;
using KC.Business.Blog;
using System.Collections.Generic;

namespace KC.Tests
{
	[TestClass()]
	public class BlogUtilsTests
	{
		[TestMethod]
		public void DetectRequestTypeTest()
		{
			Dictionary<string, string> values = new Dictionary<string, string>();
			Utils.RequestType result = Utils.DetectRequestType("http://www.kconnolly.net/", out values);
			Assert.AreEqual(Utils.RequestType.None, result);

			result = Utils.DetectRequestType("bleh", out values);
			Assert.AreEqual(Utils.RequestType.None, result);

			result = Utils.DetectRequestType("http://www.kconnolly.net/Post.aspx&ID=4", out values);
			Assert.AreEqual(Utils.RequestType.Post, result);

			result = Utils.DetectRequestType("http://www.kconnolly.net/Post.aspx&Title=mytest", out values);
			Assert.AreEqual(Utils.RequestType.Post, result);

			result = Utils.DetectRequestType("http://www.kconnolly.net/Archives.aspx/", out values);
			Assert.AreEqual(Utils.RequestType.Archives, result);

			result = Utils.DetectRequestType("http://www.kconnolly.net/Categories.aspx", out values);
			Assert.AreEqual(Utils.RequestType.Categories, result);

			result = Utils.DetectRequestType("http://www.kconnolly.net/Tags.aspx", out values);
			Assert.AreEqual(Utils.RequestType.Tags, result);
		}
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void DetectRequestTypeNullTest()
		{
			Dictionary<string, string> values;
			Utils.DetectRequestType(null, out values);
		}
	}
	[TestClass]
	public class BlogEncodingTests
	{
		[TestMethod]
		public void DecodeForEditingTest()
		{
			string input = "blah <b>blargh</b> blah";
			string expected = "blah [[b]]blargh[[/b]] blah";
			Assert.AreEqual(expected, Encoding.DecodeForEditing(input));
		}
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void DecodeForEditingNullTest()
		{
			Encoding.DecodeForEditing(null);
		}
		[TestMethod]
		public void EncodeForRenderingTest()
		{
			string input = "blah [[b]]blargh[[/b]] blah";
			string expected = "blah <b>blargh</b> blah";
			Assert.AreEqual(expected, Encoding.EncodeForRendering(input));
		}
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void EncodeForRenderingNullTest()
		{
			Encoding.EncodeForRendering(null);
		}
		[TestMethod]
		public void FormatDescriptionTest()
		{
			string input = @"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
			System.Web.UI.HtmlControls.HtmlMeta expected = new System.Web.UI.HtmlControls.HtmlMeta();
			expected.Name = "Description";
			expected.Content = input;

			System.Web.UI.HtmlControls.HtmlMeta actual = Encoding.FormatDescription(input, 1000);
			Assert.AreEqual(expected.Name, actual.Name);
			Assert.AreEqual(expected.Content, actual.Content);
		}
		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void FormatDescriptionNullTest()
		{
			Encoding.FormatDescription(null, 1000);
		}
	}
}
